<?php
use \Workerman\Autoloader;

require_once __DIR__ . '/../../../../../Workerman/Autoloader.php';
require_once __DIR__.'/../../../Config/Const.php';
Autoloader::setRootPath(__DIR__.'/../../..');

$page_groupId = GROUP_NURSERY_STOCK_MN;
$page_pageId = PAGE_RESTAURANT_LIST;

require "../framepages/moudle_base.php";

$mode = $_GET['mode'];
$result = 'normal';
if ($mode == 'delete') {
    $restaurant_id = $_GET['restaurant_id'];
    $restaurant_record = \Data\Restaurant_DAO::getRecord($restaurant_id);
    if ($restaurant_record) {
        \Data\Restaurant_DAO::delete($restaurant_record);
        $result = 'succ_delete';
    } else {
        $result = 'error_delete';
    }
}


?>



<div class="main-content">
    <div class="search-well">
        <form class="form-inline" style="margin-top: 0px;">
            用户检索 &nbsp;<input class="input-xlarge form-control"
                              placeholder="用户昵称/备注" id="4sStoreName" type="text"> &nbsp;
            <button class="btn btn-default" type="button" id="searchButton">
                <i class="fa fa-search"></i> 查找
            </button>
        </form>
    </div>
    <br />
    <div>
        <table width="100%">
            <tr>
                <th width="9%">商铺id</th>
                <th width="12%">商铺名称</th>
                <th width="15%">商铺联系人</th>
                <th>联系电话</th>
                <th>操作</th>
            </tr>
            <?php
                $needle = $_GET['needle'];
                $restaurant_list = \Data\Restaurant_DAO::getListByNeedle($needle);
                foreach ($restaurant_list as $restaurant_record) {
                    $restaurant_id = $restaurant_record->getRESTAURANT_ID();
                    $restaurant_name = $restaurant_record->getRESTAURANT_NAME();
                    $contact_name = $restaurant_record->getCONTACT_NAME();
                    $contact_number = $restaurant_record->getCONTACT_NUMBER();
                    echo "
                        <tr>
                            <td>$restaurant_id</td>
                            <td>$restaurant_name</td>
                            <td>$contact_name</td>
                            <td>$contact_number</td>
                            <td><button type='button' class='btn btn-danger' onclick='doGetInfo($restaurant_id)' >详情</button></td>
                            <td><button type='button' class='btn btn-danger' onclick='doDelete($restaurant_id)' >删除</button></td>                            
                        </tr>
                    ";
                }

            ?>

        </table>
    </div>


    <?php
    require "../framepages/footer.php";
    ?>
</div>

<script src="../lib/bootstrap/js/bootstrap.js"></script>
<script>
    $('#searchButton').click(function() {
            needle = $('#4sStoreName').val();
            url = "?needle="+needle;
            window.location.href = url;
        }
    );


    function init() {
        var msg = "<?php echo $result ?>";
        if (msg == 'succ_delete') {
            alert('删除成功');
        } else if (msg == 'err_delete') {
            alert('删除失败');
        }
    }


    function doGetInfo(restaurant_id) {
        url = "./restaurant_get_info.php?restaurant_id="+restaurant_id;
        window.location.href = url;
    }

    function doDelete(restaurant_id) {
        var r = confirm("确定要删除吗?");
        if (r) {
            url = "?mode=delete&restaurant_id="+restaurant_id;
            window.location.href = url;
        } else {
            alert("删除失败");
        }

    }
</script>
</body>
</html>